package com.hns.can.report.web;

import java.net.URLEncoder;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import com.hns.can.report.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.domain.GridPage;
import com.hns.can.common.service.CommonInitParamService;
import com.hns.can.common.web.BaseController;
import com.hns.can.master.entity.BaseLineInfoEntity;
import com.hns.can.report.service.QualityAnlsDetailService;
import com.hns.can.report.service.QualityAnlsSummaryService;
import com.hns.can.report.vo.QualityDetailParamVo;
import com.hns.frame.dao.SqlMapDao;
import com.hns.frame.mybatis.Pagination;
import com.hns.tool.export.ExportUtil;
import com.hns.tool.pub.DateTool;
import com.hns.tool.pub.PubUtil;
import com.sleepycat.je.rep.utilint.ServiceDispatcher.Response;

/**
 * 质量分析明细控制类
 *
 * @author:Chenl
 * @email:
 * @version Revision 2.0.0
 */
@Controller
@RequestMapping("/qualityAnlsDetail")
public class QualityAnlsDetailController extends BaseController {

    @Autowired
    private QualityAnlsDetailService qualityAnlsDetailService;
    @Autowired
    private CommonInitParamService commonInitParamService;
    
    //导出车辆行为明细
    final static String[] tBsStatDayBhvHeaderNames = new String[]{"企业名称","运营路线","车牌号","日期(天)","行为类型","发生次数","环比(%)","环比(%)"};
    final static String[] tBsStatDayBhvHeaderFields= new String[]{"corpName","lineName","licPltNo","reportDate","bhvType","occurCount","dayOnDay","dayOnWeak"}; 
    
    //车辆能耗统明细日报
    final static String[] tBsStatDayConsHeaderNames = new String[]{"企业名称","运营线路","车牌号","日期(天)","能源类型","差值能耗","叠加能耗","全流量能耗值","客户能耗值","线路平均能耗","能耗偏差","百公里能耗","环比(%)","同比(%)"};
    final static String[] tBsStatDayConsHeaderFields= new String[]{"corpName","lineName","licPltNo","reportDate","fuelType","maxRngEnerCons","sumRngEnerCons","tyEnerCons","custEnerCons","lineAvgEnerCons","enerConsOffset","enerConsPMile","dayOnDay","dayOnWeak"};
    
    //车辆故障明细日报
    final static String[] tBsStatDayMftHeaderNames = new String[]{"企业名称","运营线路","车牌号","日期(天)","故障类型名称","发生次数","环比(%)","同比(%)"};
    final static String[] tBsStatDayMftHeaderFields= new String[]{"corpName","lineName","licPltNo","reportDate","mftTypeName","occurCount","dayOnDay","dayOnWeak"};
 
    //车辆在线率明细日报 
    final static String[] tBsStatDayOnlineHeaderNames = new String[]{"企业名称","运营线路","车牌号","日期(天)","在线率%","基准值%","环比(%)","同比(%)"};
    final static String[] tBsStatDayOnlineHeaderFields= new String[]{"corpName","lineName","licPltNo","reportDate","onlineRate","baseLineValue","dayOnDay","dayOnWeak"};
    
    //车辆里程明细日报
    final static String[] tBsStatDayMileHeaderNames = new String[]{"企业名称","运营线路","车牌号","日期(天)","差值里程","叠加里程","全流量里程值","客户里程值","线路平均里程","里程偏差","环比(%)","同比(%)"};
    final static String[] tBsStatDayMileHeaderFields= new String[]{"corpName","lineName","licPltNo","reportDate","maxRngMile","sumRngMile","tyMile","custMile","lineAvgMile","mileOffset","dayOnDay","dayOnWeak"};

    //车辆里程明细日报
    final static String[] tBsStatDayStnHeaderNames = new String[]{"企业名称","运营线路","日期(天)","车牌号","设备编号","趟数","上行趟数","下行趟数","其他趟数","全部站数","执行站数","实际站数","无报站数量","是否包含上下行","上行缺报站","下行缺报站","其他缺报站","报站率","环比(%)","同比(%)"};
    final static String[] tBsStatDayStnHeaderFields= new String[]{"corpName","lineName","reportDate","licPltNo","eqmtCode","ranksNum","upRanksNum","dnRanksNum","otRanksNum","allStnNum","exeStnNum","realStnNum","nullStnNum","ifUpDn","upStnLost","dnStnLost","otStnLost","rpStnRate","dayOnDay","dayOnWeak"};
    /**
     * 分页查询车辆行为明细日报
     *
     * @param qualityDetailParamVo
     * @return
     * @throws Exception
     * @author:Chenl
     * @email:
     */
    @RequestMapping("/searchTBsStatDayBhvPage")
    @ResponseBody
    public Object searchOperateLogPage(QualityDetailParamVo qualityDetailParamVo) throws Exception {
    	Pagination page = null;
    	if("2".equals(qualityDetailParamVo.getCarType())){
    		page = qualityAnlsDetailService.searchTBsStatDayBhvPage(qualityDetailParamVo);
    	}else{
    		page = qualityAnlsDetailService.searchByBhvTypePage(qualityDetailParamVo);
    	}
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
    }
    
    /**
     * 导出车辆行为明细日报Pdf
     * @param qualityDetailParamVo
     * @param response
     * @throws Exception
     */
    @RequestMapping("/exportTBsStatDayBhvPdf")
    public void exportTBsStatDayBhvPdf(QualityDetailParamVo qualityDetailParamVo,HttpServletResponse response) throws Exception{
    	List<TBsStatDayBhvEntity> list = qualityAnlsDetailService.searchTBsStatDayBhvList(qualityDetailParamVo);
    	ExportUtil.exportFiles(Arrays.asList(tBsStatDayBhvHeaderNames),Arrays.asList(tBsStatDayBhvHeaderFields), list, response, "pdf", URLEncoder.encode("车辆行为明细日报表", "UTF-8")+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "车辆行为明细日报");
    }
    
    /**
     * 导出车辆行为明细日报Excel
     * @param qualityDetailParamVo
     * @param response
     * @throws Exception
     */
    @RequestMapping("/exportTBsStatDayBhvExcel")
    public void exportTBsStatDayBhvExcel(QualityDetailParamVo qualityDetailParamVo,HttpServletResponse response) throws Exception{
    	List<TBsStatDayBhvEntity> list = qualityAnlsDetailService.searchTBsStatDayBhvList(qualityDetailParamVo);
    	ExportUtil.exportFiles(Arrays.asList(tBsStatDayBhvHeaderNames),Arrays.asList(tBsStatDayBhvHeaderFields), list, response, "excel", URLEncoder.encode("车辆行为明细日报表", "UTF-8")+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "车辆行为明细日报");
    }

    /**
     * 分页查询车辆能耗明细日报
     *
     * @param qualityDetailParamVo
     * @return
     * @throws Exception
     * @author:Chenl
     * @email:
     */
    @RequestMapping("/searchTBsStatDayEnerConsPage")
    @ResponseBody
    public Object searchTBsStatDayEnerConsPage(QualityDetailParamVo qualityDetailParamVo) throws Exception {
        Pagination page = qualityAnlsDetailService.searchTBsStatDayEnerConsPage(qualityDetailParamVo);
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
    }
    /**
     * 导出车辆能耗明细日报pdf
     * @param qualityDetailParamVo
     * @param response
     * @throws Exception
     */
    @RequestMapping("exportTBsStatDayEnerConsPdf")
    public void exportTBsStatDayEnerConsPdf(QualityDetailParamVo qualityDetailParamVo,HttpServletResponse response) throws Exception{
    	List<TBsStatDayEnerConsEntity> list = qualityAnlsDetailService.searchTBsStatDayEnerConsList(qualityDetailParamVo);
    	ExportUtil.exportFiles(Arrays.asList(tBsStatDayConsHeaderNames), Arrays.asList(tBsStatDayConsHeaderFields), list, response, "pdf", URLEncoder.encode("车辆能耗明细日报表", "UTF-8")+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "车辆能耗明细日报");
    }
    
    /**
     * 导出车辆能耗明细日报excel
     * @param qualityDetailParamVo
     * @param response
     * @throws Exception
     */
    @RequestMapping("exportTBsStatDayEnerConsExcel")
    public void exportTBsStatDayEnerConsExcel(QualityDetailParamVo qualityDetailParamVo,HttpServletResponse response) throws Exception{
    	List<TBsStatDayEnerConsEntity> list = qualityAnlsDetailService.searchTBsStatDayEnerConsList(qualityDetailParamVo);
    	ExportUtil.exportFiles(Arrays.asList(tBsStatDayConsHeaderNames), Arrays.asList(tBsStatDayConsHeaderFields), list, response, "excel", URLEncoder.encode("车辆能耗明细日报表", "UTF-8")+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "车辆能耗明细日报");
    }

    /**
     * 分页查询车辆故障明细日报
     *
     * @param qualityDetailParamVo
     * @return
     * @throws Exception
     * @author:Chenl
     * @email:
     */
    @RequestMapping("/searchTBsStatDayMftPage")
    @ResponseBody
    public Object searchTBsStatWeakMftPage(QualityDetailParamVo qualityDetailParamVo) throws Exception {
    	Pagination page = null;
    	if("2".equals(qualityDetailParamVo.getCarType())){
    		page = qualityAnlsDetailService.searchTBsStatDayMftPage(qualityDetailParamVo);
    	}else{
    		page = qualityAnlsDetailService.searchByMtfTypePage(qualityDetailParamVo);
    	}
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
    }
    /**
     * 导出车辆故障明细日报pdf
     * @param qualityDetailParamVo
     * @param response
     * @throws Exception
     */
    @RequestMapping("/exportTBsStatDayMftPdf")
    public void exportTBsStatDayMftPdf(QualityDetailParamVo qualityDetailParamVo,HttpServletResponse response) throws Exception {
    	List<TBsStatDayMftEntity> list = qualityAnlsDetailService.searchTBsStatDayMftList(qualityDetailParamVo);
    	ExportUtil.exportFiles(Arrays.asList(tBsStatDayMftHeaderNames), Arrays.asList(tBsStatDayMftHeaderFields), list, response, "pdf", URLEncoder.encode("车辆故障明细日报表", "UTF-8")+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "车辆故障明细日报");
    }
    
    /**
     * 导出车辆故障明细日报excel
     * @param qualityDetailParamVo
     * @param response
     * @throws Exception
     */
    @RequestMapping("/exportTBsStatDayMftExcel")
    public void exportTBsStatDayMftExcel(QualityDetailParamVo qualityDetailParamVo,HttpServletResponse response) throws Exception {
    	List<TBsStatDayMftEntity> list = qualityAnlsDetailService.searchTBsStatDayMftList(qualityDetailParamVo);
    	ExportUtil.exportFiles(Arrays.asList(tBsStatDayMftHeaderNames), Arrays.asList(tBsStatDayMftHeaderFields), list, response, "excel", URLEncoder.encode("车辆故障明细日报表", "UTF-8")+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "车辆故障明细日报");
    }

    /**
     * 分页查询车辆里程明细日报
     *
     * @param qualityDetailParamVo
     * @return
     * @throws Exception
     * @author:Chenl
     * @email:
     */
    @RequestMapping("/searchTBsStatDayMilePage")
    @ResponseBody
    public Object searchTBsStatWeakMilePage(QualityDetailParamVo qualityDetailParamVo) throws Exception {
        Pagination page = qualityAnlsDetailService.searchTBsStatDayMilePage(qualityDetailParamVo);
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
    }
    /**
     * 导出车辆里程明细日报pdf
     * @param qualityDetailParamVo
     * @param response
     * @throws Exception
     */
    @RequestMapping("/exportTBsStatDayMilePdf")
    public void exportTBsStatDayMilePdf(QualityDetailParamVo qualityDetailParamVo,HttpServletResponse response) throws Exception {
    	List<TBsStatDayMileEntity> list = qualityAnlsDetailService.searchTBsStatDayMileList(qualityDetailParamVo);
    	ExportUtil.exportFiles(Arrays.asList(tBsStatDayMileHeaderNames), Arrays.asList(tBsStatDayMileHeaderFields), list, response, "pdf", URLEncoder.encode("车辆里程明细日报表", "UTF-8")+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "车辆里程明细日报");
    }
    
    /**
     * 导出车辆里程明细日报excel
     * @param qualityDetailParamVo
     * @param response
     * @throws Exception
     */
    @RequestMapping("/exportTBsStatDayMileExcel")
    public void exportTBsStatDayMileExcel(QualityDetailParamVo qualityDetailParamVo,HttpServletResponse response) throws Exception {
    	List<TBsStatDayMileEntity> list = qualityAnlsDetailService.searchTBsStatDayMileList(qualityDetailParamVo);
    	ExportUtil.exportFiles(Arrays.asList(tBsStatDayMileHeaderNames), Arrays.asList(tBsStatDayMileHeaderFields), list, response, "excel", URLEncoder.encode("车辆里程明细日报表", "UTF-8")+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "车辆故障明细日报");
    }

    /**
     * 分页查询车辆在线率明细日报
     *
     * @param qualityDetailParamVo
     * @return
     * @throws Exception
     * @author:Chenl
     * @email:
     */
    @RequestMapping("/searchTBsStatDayOnlinePage")
    @ResponseBody
    public Object searchTBsStatWeakOnlinePage(QualityDetailParamVo qualityDetailParamVo) throws Exception {
        Pagination page = qualityAnlsDetailService.searchTBsStatDayOnlinePage(qualityDetailParamVo);
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
    }
    /**
     * 导出车辆在线率明细日报pdf
     * @param qualityDetailParamVo
     * @param response
     * @throws Exception
     */
    @RequestMapping("/exportTBsStatDayOnlinePdf")
    public void exportTBsStatDayOnlinePdf(QualityDetailParamVo qualityDetailParamVo,HttpServletResponse response) throws Exception {
    	List<TBsStatDayOnlineEntity> list = qualityAnlsDetailService.searchTBsStatDayOnlineList(qualityDetailParamVo);
    	ExportUtil.exportFiles(Arrays.asList(tBsStatDayOnlineHeaderNames), Arrays.asList(tBsStatDayOnlineHeaderFields), list, response, "pdf", URLEncoder.encode("车辆在线明细日报表", "UTF-8")+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "车辆在线明细日报");
    }
    
    /**
     * 导出车辆在线率明细日报excel
     * @param qualityDetailParamVo
     * @param response
     * @throws Exception
     */
    @RequestMapping("/exportTBsStatDayOnlineExcel")
    public void exportTBsStatDayOnlineExcel(QualityDetailParamVo qualityDetailParamVo,HttpServletResponse response) throws Exception {
    	List<TBsStatDayOnlineEntity> list = qualityAnlsDetailService.searchTBsStatDayOnlineList(qualityDetailParamVo);
    	ExportUtil.exportFiles(Arrays.asList(tBsStatDayOnlineHeaderNames), Arrays.asList(tBsStatDayOnlineHeaderFields), list, response, "excel", URLEncoder.encode("车辆在线明细日报表", "UTF-8")+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "车辆在线明细日报");
    }

    /**
     * 查询车辆报站明细
     * @param qualityDetailParamVo
     * @return
     * @throws Exception
     */
    @RequestMapping("/searchTBsStatDayStnPage")
    @ResponseBody
    public Object searchTBsStatDayStnPage (QualityDetailParamVo qualityDetailParamVo) throws Exception {
        Pagination page = qualityAnlsDetailService.searchTBsStatDayStnPage(qualityDetailParamVo);
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
    }

    /**
     * 导出车辆在线率明细日报pdf
     * @param qualityDetailParamVo
     * @param response
     * @throws Exception
     */
    @RequestMapping("/exportTBsStatDayStopPdf")
    public void exportTBsStatDayStnPdf(QualityDetailParamVo qualityDetailParamVo,HttpServletResponse response) throws Exception {
        List<TBsStatDayStnEntity> list = qualityAnlsDetailService.searchTBsStatDayStnList(qualityDetailParamVo);
        ExportUtil.exportFiles(Arrays.asList(tBsStatDayStnHeaderNames), Arrays.asList(tBsStatDayStnHeaderFields), list, response, "pdf", URLEncoder.encode("车辆报站明细日报表", "UTF-8")+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "车辆报站明细日报");
    }

    /**
     * 导出车辆在线率明细日报Excel
     * @param qualityDetailParamVo
     * @param response
     * @throws Exception
     */
    @RequestMapping("/exportTBsStatDayStopExcel")
    public void exportTBsStatDayStnExcel(QualityDetailParamVo qualityDetailParamVo,HttpServletResponse response) throws Exception {
        List<TBsStatDayStnEntity> list = qualityAnlsDetailService.searchTBsStatDayStnList(qualityDetailParamVo);
        ExportUtil.exportFiles(Arrays.asList(tBsStatDayStnHeaderNames), Arrays.asList(tBsStatDayStnHeaderFields), list, response, "excel", URLEncoder.encode("车辆报站明细日报表", "UTF-8")+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "车辆报站明细日报");
    }

   
}
